package com.ustadzmenjawab.indexing;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import com.ustadzmenjawab.server.DBConnFactory;

public class IDBAccess {
	public List<Hashtable<String,String>> getAllDBArtikel(){
		Connection conn = DBConnFactory.getConnectionWODataSource();
		String sql = "Select * From ustadzmenjawabdb_prod";
		try {
			PreparedStatement ps = conn.prepareStatement(sql);
			ResultSet rs = ps.executeQuery(sql);
			ResultSetMetaData metaData = rs.getMetaData();
			int rowCount = metaData.getColumnCount();
			List<Hashtable<String,String>> ls = new ArrayList<Hashtable<String,String>>();
			while(rs.next()){
				  Hashtable<String,String> rec = new Hashtable<String,String>();
				  for (int i = 0; i < rowCount; i++) {
					  String colName = metaData.getColumnName(i + 1);
					  String val = rs.getString(colName);
					  rec.put(colName, val);
				  }
				  ls.add(rec);
			}
			if(ls.size() == 0)
				return null;
			return ls;
		} catch (SQLException e) {
		
			e.printStackTrace();
		}
		return null;
		
	}
	
}
